<?php

namespace addons\Patrol\common\models;

use Yii;
use common\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%addon_oa_place}}".
 *
 * @property int $id ID
 * @property string $name 巡更点名称
 * @property string $label 标签ID
 * @property string $mark 备注
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 修改时间
 */
class PatrolPlace extends \common\models\base\BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%addon_patrol_place}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'label'], 'required'],
            [['status', 'created_at', 'updated_at'], 'integer'],
            [['name', 'label'], 'string', 'max' => 32],
            [['mark'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '巡更地点',
            'label' => '标签ID',
            'mark' => '备注',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    /**
     * 下拉
     *
     * @return \yii\db\ActiveQuery
     */
    public static function getDropDown()
    {
        $models = PatrolPlace::find()
            ->select(['id', 'name'])
            ->andFilterWhere(['merchant_id' => Yii::$app->user->identity->merchant_id])
            ->orderBy('id asc,name asc')
            ->asArray()
            ->all();
        return ArrayHelper::map($models, 'id', 'name');
    }

    public function beforeSave($insert)
    {
        $this->merchant_id = Yii::$app->user->identity->merchant_id;

        return parent::beforeSave($insert);

    }
}